package com.sojson.config.shardingJdbc;

import java.util.Properties;

import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;

import com.sojson.util.id.IdUtil;

import lombok.Getter;
import lombok.Setter;

/**
 * @description: 原生雪花算法生成出来的id在低并发下存在分布不均的问题
 * 参考美团点评方案修改
 * @link https://github.com/Meituan-Dianping/Leaf/blob/master/leaf-core/src/main/java/com/sankuai/inf/leaf/snowflake/SnowflakeIDGenImpl.java
 * 只修改了下个毫秒的起始位置
 **/
public class CustomShardingSnowflakeIdGenerator implements KeyGenerateAlgorithm {

    @Getter
    private final String type = "SNOWFLAKE";

    @Getter
    @Setter
    private Properties props = new Properties();

    @Override
    public void init(Properties props) {

    }

    @Override
    public Comparable<?> generateKey() {
        return IdUtil.snowflakeId();
    }

}